<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();

/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop();


echo('
<script language="javascript" type="text/javascript" src="js/inc/list.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/member.js?v='. OT_VERSION .'"></script>
');


$MB->IsMenuRight('alertBack','用户管理');


switch($mudi){
	case 'add':
		AddOrRev();
		break;

	case 'rev':
		AddOrRev();
		break;

	default :
		manage();
		break;
}

$skin->WebBottom();

$MB->Close();
$DB->Close();





// 新增、修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$dataTypeCN;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');
	$backURL		= OT::GetStr('backURL');
	$dataID			= OT::GetInt('dataID');

	if ($mudi == 'rev'){
		$revexe = $DB->query('select * from '. OT_dbPref .'member where MB_ID='. $dataID);
		if (! $row = $revexe->fetch()){
			JS::AlertBackEnd('无该记录！');
		}
		$MB_time		= $row['MB_time'];
		$MB_loginTime	= $row['MB_loginTime'];
		$MB_loginNum	= $row['MB_loginNum'];
		$MB_loginIP		= $row['MB_loginIP'];
		$MB_realname	= $row['MB_realname'];
		$MB_username	= $row['MB_username'];
		$MB_userpwd		= $row['MB_userpwd'];
		$MB_userKey		= $row['MB_userKey'];
		$MB_right		= $row['MB_right'];
		$MB_groupID		= $row['MB_groupID'];
		$MB_rightStr	= $row['MB_rightStr'];
		$MB_itemNum		= $row['MB_itemNum'];
		$MB_state		= $row['MB_state'];
		$MB_foreUsername = $row['MB_foreUsername'];
		$MB_note		= $row['MB_note'];
		$MB_isEndTime	= $row['MB_isEndTime'];
		$MB_endTime		= $row['MB_endTime'];
		unset($revexe);

		$mudiCN = '修改';
	}else{
		$MB_time		= '';
		$MB_loginTime	= '';
		$MB_loginNum	= '';
		$MB_loginIP		= '';
		$MB_realname	= '';
		$MB_username	= '';
		$MB_userpwd		= '';
		$MB_userKey		= '';
		$MB_right		= '';	// 没用
		$MB_groupID		= 0;
		$MB_rightStr	= '';
		$MB_itemNum		= 20;
		$MB_state		= 1;
		$MB_foreUsername = '';
		$MB_note		= '';
		$MB_isEndTime	= 0;
		$MB_endTime		= '';

		$mudiCN = '添加';
	}

	echo(
	AdmArea::TopBackBtn('member.php?mudi=manage&dataTypeCN='. urlencode($dataTypeCN)) .'

	<form id="dealForm" name="dealForm" method="post" action="member_deal.php?mudi='. $mudi .'&nohrefStr=close" onsubmit="return CheckForm()">
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataMode" name="dataMode" value="'. $dataMode .'" />
	<input type="hidden" id="dataModeStr" name="dataModeStr" value="'. $dataModeStr .'" />
	<input type="hidden" id="dataID" name="dataID" value="'. $dataID .'" />
	'. Area::BackUrlInput($backURL) .'

	<div class="tabMenu">
	<ul>
		<li rel="tabInfo" class="selected">基本信息</li>
	</ul>
	</div>

	<div class="tabMenuArea">
		<table id="tabInfo" cellpadding="0" cellspacing="0" summary="" class="padd5td">
		<tr><td class="tabLeftWidth"></td><td></td></tr>
		<tr>
			<td align="right">添加时间：</td>
			<td>'. $MB_time .'</td>
		</tr>
		<tr>
			<td align="right">最后登录时间：</td>
			<td>'. $MB_loginTime .'  （共登录 '. $MB_loginNum .' 次）</td>
		</tr>
		<tr>
			<td align="right">最后登录IP：</td>
			<td>'. $MB_loginIP .'</td>
		</tr>
		<tr>
			<td align="right">'. Skin::RedSign() .'到期时间：</td>
			<td align="left">
				<label><input type="checkbox" id="isEndTime" name="isEndTime" value="1" '. Is::Checked($MB_isEndTime,1) .' onclick="CheckEndTime()" />开启到期时间</label>
				<span id="endTimeBox" style="display:none;">
					<input type="text" id="endTime" name="endTime" size="22" style="width:170px;" value="'. $MB_endTime .'" onfocus=\'WdatePicker({dateFmt:"yyyy-MM-dd HH:mm:ss"})\' class="Wdate" />&ensp;&ensp;
					'. (empty($MB_endTime) == false ? '<span style="color:red;">['. TimeDate::Get('date',$MB_endTime) .'&ensp;'. TimeDate::DiffDayCN($MB_endTime,'还剩') .']</span>' : '') .'
				</span>
			</td>
		</tr>
		<tr>
			<td align="right">'. Skin::RedSign() .'用户组：</td>
			<td>
				<select id="groupID" name="groupID">
					<option value="">&ensp;</option>
					');
					$readexe = $DB->query('select MG_ID,MG_theme,MG_rightStr from '. OT_dbPref .'memberGroup');
					while($row = $readexe->fetch()){
						if (! ($MB->GetRightStr() != 'admin' && strpos($row['MG_rightStr'],'|用户管理|') !== false)){
							echo('<option value="'. $row['MG_ID'] .'" '. Is::Selected($row['MG_ID'], $MB_groupID) .'>'. $row['MG_theme'] .'</option>');
						}
					}
					unset($readexe);
				echo('
				</select>
			</td>
		</tr>
		<tr>
			<td align="right">'. Skin::RedSign() .'用户名：</td>
			<td>
				<input type="text" id="username" name="username" class="text" style="width:250px;" maxlength="32" value="'. $MB_username .'" />
				长度4~16字节，仅允许 数字、英文、汉字、下划线
			</td>
		</tr>
		<tr>
			<td align="right">'. ($mudi == 'rev' ? '' : Skin::RedSign()) .'密码：</td>
			<td>
				<input type="password" id="userpwd" name="userpwd" class="text" style="width:250px;" maxlength="32" />
				<input type="button" onclick="ResetPwd()" value="默认密码：123456">
				'. ($mudi == 'rev' ? '<span style="color:blue;">&ensp;不改密码请留空</span>' : '') .'
			</td>
		</tr>
		<tr>
			<td align="right">称呼：</td>
			<td>
				<input type="text" id="realname" name="realname" class="text" style="width:250px;" maxlength="32" value="'. $MB_realname .'" />
			</td>
		</tr>
		<tr>
			<td align="right">列表每页条数：</td>
			<td>
				<input type="text" id="itemNum" name="itemNum" class="text" style="width:50px;" value="'. $MB_itemNum .'" />
			</td>
		</tr>
		<tr>
			<td align="right">默认指向前台用户名：</td>
			<td>
				<input type="text" id="foreUsername" name="foreUsername" class="text" style="width:250px;" value="'. $MB_foreUsername .'" />
			</td>
		</tr>
		<tr>
			<td align="right" valign="top" style="padding-top:6px;">备注：</td>
			<td>
				<textarea id="note" name="note" cols="40" rows="4" style="width:250px;">'. $MB_note .'</textarea>
			</td>
		</tr>
		<tr>
			<td align="right">状态：</td>
			<td>
				<label><input type="radio" name="state" value="0" '. Is::Checked($MB_state,0) .' />正常</label>&ensp;&ensp;
				<label><input type="radio" name="state" value="10" '. Is::Checked($MB_state,10) .' />冻结</label>&ensp;&ensp;
			</td>
		</tr>
		<tr style="display:none;">
			<td align="right">权限集：</td>
			<td>'. $MB_rightStr .'</td>
		</tr>
		</table>

		<div class="tabMenuSubmit"><input type="image" src="'. AdmTpl::ImgSrc('button_'. $mudi) .'" /></div>
	</div>

	</form>
	');

}



function manage(){
	global $DB,$MB,$skin,$MB,$mudi,$pageCount,$recordCount,$dataType,$dataTypeCN;

	$refUsername	= OT::GetRegExpStr('refUsername','sql');
	$refRealname	= OT::GetRegExpStr('refRealname','sql');
	$refGroupID		= OT::GetInt('refGroupID');
	$refState		= OT::GetInt('refState',-1);

	$SQLstr='select MB.MB_ID,MB.MB_username,MB.MB_realname,MB.MB_rightStr,MB.MB_time,MB.MB_state,MB.MB_isEndTime,MB.MB_endTime,MB.MB_note,MG.MG_theme from '. OT_dbPref .'member as MB LEFT JOIN '. OT_dbPref .'memberGroup as MG on MB.MB_groupID=MG.MG_ID where MB.MB_ID>=2';

	if ($refUsername != ''){ $SQLstr = $SQLstr ." and MB_username like '%". $refUsername ."%'"; }
	if ($refRealname != ''){ $SQLstr = $SQLstr ." and MB_realname like '%". $refRealname ."%'"; }
	if ($refGroupID > 0){ $SQLstr = $SQLstr .' and MB_groupID='. $refGroupID; }
	if ($refState > -1){ $SQLstr = $SQLstr .' and MB_state='. $refState; }

	$skin->TableTop('share_refer.gif','','用户查询');
		echo('
		<form id="refForm" name="refForm" method="get" action="">
		<input type="hidden" name="mudi" value="'. $mudi .'" />
		<table align="center" cellpadding="0" cellspacing="0" summary="" class="padd3td"><tr>
			<td>
				&ensp;&ensp;用户名：<input type="text" id="refUsername" name="refUsername" size="10" value="'. $refUsername .'" />
			</td>
			<td>
				&ensp;&ensp;称呼：<input type="text" id="refRealname" name="refRealname" size="8" value="'. $refRealname .'" />
			</td>
			<td>
				&ensp;&ensp;用户组：<select id="refGroupID" name="refGroupID">
						<option value="">&ensp;</option>
						');
						$readexe=$DB->query('select MG_ID,MG_theme from '. OT_dbPref .'memberGroup');
							while($row = $readexe->fetch()){
								echo('<option value="'. $row['MG_ID'] .'" '. Is::Selected($refGroupID,$row['MG_ID']) .'>'. $row['MG_theme'] .'</option>');
							}
						unset($readexe);
					echo('
					</select>
			</td>
			<td>
				&ensp;&ensp;状态：<select id="refState" name="refState">
						<option value="">&ensp;</option>
						<option value="0" '. Is::Selected($refState,0) .'>正常</option>
						<option value="10" '. Is::Selected($refState,10) .'>冻结</option>
					</select>
			</td>
			<td>&ensp;&ensp;</td>
			<td><input type="image" src="'. AdmTpl::ImgSrc('button_refer') .'" /></td>
		</tr>
		</table>
		</form>
		');
	$skin->TableBottom();

	echo('
	<div style="padding:6px;">
		<input type="button" value="添加用户" onclick=\'document.location.href="?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&backURL="+ encodeURIComponent(document.location.href);\' />&ensp;&ensp;&ensp;&ensp;
	</div>
	');

	$skin->TableTop2('share_userList.gif','','用户列表');
	$skin->TableItemTitle('6%,6%,12%,11%,9%,11%,20%,13%,12%','序号,ID号,用户名,称呼,状态,用户组,备注/到期时间,加入时间,<!-- 授权　 -->修改　删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		// 每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit($SQLstr .' order by MB.MB_ID DESC',$pageSize,$page);
	if (! $showRow){
		$skin->TableNoData();
	}else{
		$recordCount=$DB->GetRowCount();
		$pageCount=ceil($recordCount/$pageSize);
		if ($page < 1 || $page > $pageCount){$page=1;}

		echo('
		<tbody class="tabBody padd3td">
		');
		$number=1+($page-1)*$pageSize;
		$rowCount = count($showRow);
		for ($i=0; $i<$rowCount; $i++){
			if ($i % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }

			$endTimeStr = '';
			if ($showRow[$i]['MB_isEndTime'] == 1){
				$endTimeStr = '
					<div>
						'. $showRow[$i]['MB_endTime'] .'
						<div style="color:red;">['. TimeDate::DiffDayCN($showRow[$i]['MB_endTime'],'剩') .']</div>
					</div>
					';
			}

			echo('
			<tr id="data'. $showRow[$i]['MB_ID'] .'" '. $bgcolor .'>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['MB_ID'] .'</td>
				<td align="center">'. $showRow[$i]['MB_username'] .'</td>
				<td align="center">'. $showRow[$i]['MB_realname'] .'</td>
				<td align="center">'. ($showRow[$i]['MB_state']==10 ? '<span class="font2_2">冻结</span>' : '正常') .'</td>
				<td align="center">'. $showRow[$i]['MG_theme'] .'</td>
				<td align="center">'. $showRow[$i]['MB_note'] . $endTimeStr .'</td>
				<td align="center">'. $showRow[$i]['MB_time'] .'</td>
				<td align="center">
					<img src="images/img_rev.gif" style="cursor:pointer" onclick=\'document.location.href="?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['MB_ID'] .'&backURL="+ encodeURIComponent(document.location.href)\' alt="修改" title="修改" />&ensp;&ensp;
					<img src="images/img_del.gif" style="cursor:pointer" onclick=\'if(confirm("你确定要删除？")==true){DataDeal.location.href="member_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['MB_username']) .'&dataID='. $showRow[$i]['MB_ID'] .'"}\' alt="删除" title="删除" />
				</td>
			</tr>
			');
			$number ++;
		}
		echo('
		</tbody>
		');
	}
	unset($showRow);

	$skin->TableBottom2($pageCount, $pageSize, $recordCount);

}

?>